<?php 
/**
 * Description of form
 * @author diotheos
 * @since 7 мая 2010
 */
class App_Form_Search_Extended extends Lib_Form_Clear{
	/**
	 * Initialization of form function
	 * 
	 * @since 7 мая 2010
	 * @author diotheos
	 * @return Zend_Form
	 */
	public function init(){
		
/* Initialization section
 **************************************************************************************************/		
		parent::init();
		$this->setMethod('get');
        $this->setAction('search');
        $this->setAttrib('class','search-widget');
        
/* General section
 **************************************************************************************************/
        $category = new Zend_Form_Element_Select('category');
        $this->addElement($category);
        
        $generalSet = new Zend_Form_SubForm();
        $general = new Zend_Form_SubForm();
        
        $general->addElements(array(
            new Zend_Form_Element_Select('mark',array(
                    'label'=>_('Марка'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'mark-model[0]',
                    'class' => 'styled'
            )),
            new Zend_Form_Element_Select('model',array(
                    'label'=>_('Модель'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'mark-model[0]',
                    'class' => 'styled'
                    
            ))
        ));
        
        $generalSet->addSubForm($general,'0',1);
        $this->addSubForm($generalSet,'general',10);
        
/* Year section
 **************************************************************************************************/
        $year = new Zend_Form_SubForm();
        $year->setLegend(_('Год выпуска'));
        $year->addElements(array(
            new Zend_Form_Element_Select('from',array(
                    'label'=>_('От'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[year]',
                    'class' => 'styled'
            )),
            new Zend_Form_Element_Select('to',array(
                    'label'=>_('До'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[year]',
            		'class' => 'styled'
                    
            ))
        ));
//        $year->setAttrib('class', 'hide-labels');
        
        $this->addSubForm($year,'year', 20);
        
/* Price section
 **************************************************************************************************/
        $price = new Zend_Form_SubForm();
        $price->setLegend(_('Цена'));
        $price->addElements(array(
            new Zend_Form_Element_Text('from',array(
                    'label'=>_('От'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[price]',
                    
            )),
            new Zend_Form_Element_Text('to',array(
                    'label'=>_('До'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[price]',
                    
            )),
            new Zend_Form_Element_Select('currency', array(
                	'label'=>'',
                    'decorators' => array('ViewHelper'),
            		'belongsTo' => 'params[price]',
                    'class' => 'styled'
            ))
	    ));
        $this->addSubForm($price,'price', 30);

/* Fuel section
 **************************************************************************************************/
        $fuel = new Zend_Form_Element_Select('fuel');
        $fuel->setOptions(array(
            'order'=>40,
            'label'=>_('Топливо'),
            'belongsTo' => 'params',
            'class' => 'styled'
            
        ));
//        $fuel->setAttrib('class', 'semi-column');
        $this->addElement($fuel);
        
/* Placement section
 **************************************************************************************************/
        $placementSet = new Zend_Form_SubForm();
        $placement = new Zend_Form_SubForm();

        $placement->addElements(array(
            new Zend_Form_Element_Select('state',array(
                    'label'=>_('Область'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'state-city[0]',
                    'class' => 'styled'
            )),
            new Zend_Form_Element_Select('city',array(
                    'label'=>_('Город'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'state-city[0]',
                    'class' => 'styled'
                    
            ))
        ));
        
        $placementSet->addSubForm($placement,0);
        $this->addSubForm($placementSet,'placement', 50);
        
/* Body section
 **************************************************************************************************/        
        $body = new Zend_Form_Element_Select('body');
        $body->setOptions(array(
            'order'=>60,
            'label'=>_('Тип кузова'),
            'belongsTo' => 'params',
            'class' => 'styled'
        ));
        $this->addElement($body);

/* Mileage section
 **************************************************************************************************/
        $mileage = new Zend_Form_SubForm();
        $mileage->setLegend(_('Пробег'));
        $mileage->addElements(array(
            new Zend_Form_Element_Text('from',array(
                    'label'=>_('От'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[mileage]',
                    
            )),
            new Zend_Form_Element_Text('to',array(
                    'label'=>_('Пробег до'),
                    'decorators'=>array('ViewHelper'),
                    'belongsTo' => 'params[mileage]',
                    
            ))
        ));
        $this->addSubForm($mileage,'mileage', 70);

/* Gear section
 **************************************************************************************************/
        $gear = new Zend_Form_Element_Select('gear');
        $gear->setOptions(array(
            'order'=>80,
            'label'=>_('Коробка передач'),
            'belongsTo' => 'params',
            'class' => 'styled'
        ));
        $this->addElement($gear);
        
/* Drive section
 **************************************************************************************************/
        $drive = new Zend_Form_Element_Select('drive');
        $drive->setOptions(array(
            'order'=>90,
            'label'=>_('Привод'),
            'class' => 'styled'
        ));
        $this->addElement($drive);
        
/* Color section
 **************************************************************************************************/
        $color = new Zend_Form_Element_Select('color');
        $color->setOptions(array(
            'order'=>100,
            'label'=>_('Цвет'),
            'belongsTo' => 'params',
            'class' => 'styled'
        ));
        $this->addElement($color);   
             
        $isMetalicColor = new Zend_Form_Element_Checkbox('is_metalic_color');
        $isMetalicColor->setOptions(array(
            'order'=>110,
            'label'=>_('Металлик'),
            'belongsTo' => 'params',
            
        ));
        $this->addElement($isMetalicColor);
        
/* Exchange section
 **************************************************************************************************/        
        $exchange = new Zend_Form_Element_Select('exchange');
        $exchange->setOptions(array(
            'order'=>120,
            'label'=>_('Обмен'),
            'belongsTo' => 'params',
            'class' => 'styled'
        ));
        $this->addElement($exchange);

/* Credit sectionCheckbox
 **************************************************************************************************/        
        $credit = new Zend_Form_Element_Select('credit');
        $credit->setOptions(array(
            'order'=>130,
            'label'=>_('Кредит'),
            'belongsTo' => 'params',
            'class' => 'styled'
        ));
        $this->addElement($credit);        
       
/* Damage section
 **************************************************************************************************/        
        $damage = new Zend_Form_Element_Select('damage');
        $damage->setOptions(array(
            'order'=>140,
            'label'=>_('Повреждения'),
            'belongsTo' => 'params',
            'class' => 'styled'
        ));
        $this->addElement($damage); 

/* Condition section
 **************************************************************************************************/        
        $condition = new Zend_Form_Element_Select('condition');
        $condition->setOptions(array(
            'order'=>150,
            'label'=>_('Состояние'),
            'belongsTo' => 'params',
            'class' => 'styled'
        ));
        $this->addElement($condition);  
               
/* Custom section
 **************************************************************************************************/        
        $custom = new Zend_Form_Element_Select('custom');
        $custom->setOptions(array(
            'order'=>150,
            'label'=>_('Растаможка'),
            'belongsTo' => 'params',
            'class' => 'styled'
        ));
        $this->addElement($custom);
        
///* Door section
// **************************************************************************************************/        
//        $doorCount = new Zend_Form_Element_Select('doorCount');
//        $doorCount->setOptions(array(
//            'order'=>160,
//            'label'=>_('Количество дверей')
//        ));
//        $this->addElement($doorCount);

//        
//        $sittingCount = new Zend_Form_Element_Select('sitting_count');
//        $sittingCount->setLabel( _('Количество сидений'));
//        $this->addElement($sittingCount);
//        
        $photoCount = new Zend_Form_Element_Checkbox('photo_count');
        $photoCount->setLabel( _('Только с фото'));
        $photoCount->setBelongsTo('params');
        $this->addElement($photoCount);

        $submit  = new Zend_Form_Element_Submit('search');
        $submit->setOptions(array(
            'order'=>990,
            'label'=>_('Поиск'),
            
        ));
        $this->addElement($submit);
	      
        $this->setDecorators(array(
            array('ViewScript', array('viewScript'=>'forms/search/extended.phtml', 'class'=> 'form element'))
        ));
        
		return $this;
	}
}